<template>
	<view class="home-view">
		<view class="course-top">
			<view class="title">育儿商城</view>
			<view class="more" @click="mallClick">更多商品</view>
		</view>

		<view v-if="shop" class="mall-view" @click="goodClick">
			<u-image width="100%" height="460" border-radius="20rpx" :src="formatCover(shop.pic)"></u-image>
			<view class="mall-info-view">
				<view class="mall-info">
					<view class="name">
						{{shop.name}}
					</view>
					<view class="count">
						收藏数量 {{shop.likeNum}}
					</view>
				</view>
				<!-- 				<view class="action-view">
							<view class="item1">
								<u-icon name="shopping-cart" color="#ffffff"></u-icon>
							</view>
							<view class="item2">
								<u-icon name="shopping-cart-fill" color="#DA473A"></u-icon>
							</view>
						</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import appMixin from '@/mixins/app.js'
	import { getGoodHot } from '@/api/shop.js'
	export default {
		mixins: [appMixin],
		data() {
			return {
				shop: null,
			}
		},
		onLoad() {
			this.shopUrl = 'https://s.xxwbaby.com';
			const appDebug = uni.getStorageSync('appDebug');
			if (appDebug) {
				this.shopUrl = 'http://s.dotflat.cn';
			}
			// uni.showLoading({});
			// setTimeout(()=> {
			// 	uni.hideLoading();
			// }, 2000)
		},
		onShow() {
			const ticket = uni.getStorageSync('ticket');
			if (!this.$u.test.isEmpty(ticket)) {
				this.getShopGoods();
			}
		},
		methods: {
			goodClick() {
				let ticket = ''
				try {
					ticket = uni.getStorageSync('ticket');
				} catch (e) {}
				if (this.$u.test.isEmpty(ticket)) {
					this.$u.toast('token失效，请重新登录');
					return;
				}
				console.log(this.shopUrl)
				// #ifdef H5
				    window.location.href=`${this.shopUrl}/#/pages/goods/goods?id=${this.shop.id}&ticket=${ticket}`;
				// #endif

				// #ifdef APP-PLUS
					this.$u.route({
						url: '/pages_base/common/webview',
						params: {
							url: encodeURIComponent(`${this.shopUrl}/#/pages/goods/goods?id=${this.shop.id}&ticket=${ticket}`)
						}
					})
				// #endif
			},
			
			mallClick() {
				let ticket = ''
				try {
					ticket = uni.getStorageSync('ticket');
				} catch (e) {}
				if (this.$u.test.isEmpty(ticket)) {
					this.$u.toast('token失效，请重新登录');
					return;
				}
				
				// #ifdef H5
				    window.location.href=`${this.shopUrl}/#/?ticket=${ticket}`;
				// #endif
				
				// #ifdef APP-PLUS
					this.$u.route({
						url: '/pages_base/common/webview',
						params: {
							url: encodeURIComponent(`${this.shopUrl}/#/?ticket=${ticket}`)
						}
					})
				// #endif
			},
			
			formatCover(pic) {
				return `${this.shopUrl}/prod-api/file/getImgStream?idFile=${pic}`;
			},
			
			getShopGoods() {
				getGoodHot().then(res => {
					console.log(res);
					this.shop = res.data[0];
				})
			}
		}
	}
</script>

<style lang="scss">
	.home-view{
		padding-left: $app-page-padding;
		padding-right: $app-page-padding;
		margin-bottom: $app-page-padding;
		
		.course-top{
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin-top: 30rpx;
			
			.title{
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 38rpx;
			}
			
			.more{
				font-size: 18rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #999999;
				line-height: 38rpx;
			}
		}
		
		.mall-view{
			margin-top: 30rpx;
			
			.mall-info-view{
				margin-top: 30rpx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				
				.mall-info{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					width: 100%;
					
					.name{
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #333333;
						line-height: 30rpx;
					}
					
					.count{
						font-size: 18rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 30rpx;
					}
				}
				
				.action-view{
					display: flex;
					flex-direction: row;
					
					.item1{
						width: 50rpx;
						height: 50rpx;
						background: #DA473A;
						border: 1rpx solid #DA473A;
						border-radius: 50%;
						display: flex;
						justify-content: center;
						align-items: center;
					}
					
					.item2{
						width: 50rpx;
						height: 50rpx;
						background: #FFFFFF;
						border: 1rpx solid #DA473A;
						border-radius: 50%;
						display: flex;
						justify-content: center;
						align-items: center;
						margin-left: 20rpx;
					}
				}
			}
		}
	}

</style>
